GCC-FLAGS-KERNEL = "-std=c99" -m32 -D KERNEL -nostdlib -nostdinc -fno-builtin -fleading-underscore
GCC-FLAGS-PROGRAM = "-std=c99" -m32 -D PROGRAM -g -O3

#MAKE AS WINDOWS/LINUX PROGRAM
program : interpreter/*.c interpreter/*.h oceania.image
	gcc $(GCC-FLAGS-PROGRAM) interpreter/interpreter.c -o program
	
#MAKE AS KERNEL
kernel.bin: primordialsoup/*.s primordialsoup/*.c primordialsoup/*.h primordialsoup/link.ld interpreter/*.c interpreter/*.h
	nasm -f elf -o entry.o primordialsoup/entry.s
	nasm -f elf -o prim16int.o primordialsoup/prim16int.s
	nasm -f elf -o dtables.o primordialsoup/dtables.s
	nasm -f elf -o interrupt.o primordialsoup/interrupt.s
	nasm -f elf -o terminal.o primordialsoup/terminal.s
	nasm -f elf -o virtual.o primordialsoup/virtual.s
	nasm -f elf -o common.o primordialsoup/common.s
	gcc $(GCC-FLAGS-KERNEL) -O3 -o interpreter.o -c interpreter/interpreter.c
	gcc $(GCC-FLAGS-KERNEL) -o primordialsoup.o -c primordialsoup/primordialsoup.c 
	ld -T primordialsoup/link.ld -o kernel.bin *.o
	objcopy -O elf32-i386 kernel.bin
	rm *.o

#MAKE BOOTABLE CD
oceania.iso : kernel.bin oceania.image grub/*
	mkdir -p iso/boot/grub
	cp grub/stage2_eltorito iso/boot/grub
	cp grub/menu.lst iso/boot/grub
	cp kernel.bin iso
	cp oceania.image iso
	mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o oceania.iso iso
	
#MAKE BOOTABLE FLASH DRIVE
install-kernel : kernel.bin oceania.image
	cp kernel.bin ../boot/kernels/oceania
	cp oceania.image ../boot/modules/oceania.image

oceania.image : 
	wget http://sites.google.com/site/rmacnak/files/oceania.zip -O oceania.zip
	unzip -u oceania.zip
	
clean :
	rm -f *.o
	rm -f program program.exe program.exe.stackdump kernel.bin oceania.iso
	rm -rf iso
	rm -rf build
